package com.gitee.wsl.compose.mvi.merge

import androidx.compose.foundation.interaction.InteractionSource
import androidx.compose.foundation.text.selection.LocalTextSelectionColors
import androidx.compose.foundation.text.selection.TextSelectionColors
import androidx.compose.material3.TextFieldColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.graphics.Color
import com.gitee.wsl.ext.any.notSameAs
import com.gitee.wsl.ext.any.sameAs

class TextFieldColorsMerger : ComponentMerger<TextFieldColors> {
    override val default: TextFieldColors = Default

    companion object {
        @Stable
        val Default = TextFieldColors(
            focusedTextColor = Color.Unspecified,
            unfocusedTextColor = Color.Unspecified,
            disabledTextColor =Color.Unspecified,
            errorTextColor = Color.Unspecified,
            focusedContainerColor = Color.Unspecified,
            unfocusedContainerColor = Color.Unspecified,
            disabledContainerColor = Color.Unspecified,
            errorContainerColor = Color.Unspecified,
            cursorColor = Color.Unspecified,
            errorCursorColor = Color.Unspecified,
            textSelectionColors = unspecifiedTextSelectionColors,
            focusedIndicatorColor = Color.Unspecified,
            unfocusedIndicatorColor = Color.Unspecified,
            disabledIndicatorColor = Color.Unspecified,
            errorIndicatorColor = Color.Unspecified,
            focusedLeadingIconColor = Color.Unspecified,
            unfocusedLeadingIconColor = Color.Unspecified,
            disabledLeadingIconColor = Color.Unspecified,
            errorLeadingIconColor =Color.Unspecified,
            focusedTrailingIconColor = Color.Unspecified,
            unfocusedTrailingIconColor = Color.Unspecified,
            disabledTrailingIconColor = Color.Unspecified,
            errorTrailingIconColor = Color.Unspecified,
            focusedLabelColor = Color.Unspecified,
            unfocusedLabelColor = Color.Unspecified,
            disabledLabelColor = Color.Unspecified,
            errorLabelColor = Color.Unspecified,
            focusedPlaceholderColor = Color.Unspecified,
            unfocusedPlaceholderColor = Color.Unspecified,
            disabledPlaceholderColor = Color.Unspecified,
            errorPlaceholderColor = Color.Unspecified,
            focusedSupportingTextColor = Color.Unspecified,
            unfocusedSupportingTextColor = Color.Unspecified,
            disabledSupportingTextColor = Color.Unspecified,
            errorSupportingTextColor = Color.Unspecified,
            focusedPrefixColor = Color.Unspecified,
            unfocusedPrefixColor = Color.Unspecified,
            disabledPrefixColor = Color.Unspecified,
            errorPrefixColor = Color.Unspecified,
            focusedSuffixColor = Color.Unspecified,
            unfocusedSuffixColor = Color.Unspecified,
            disabledSuffixColor = Color.Unspecified,
            errorSuffixColor = Color.Unspecified
        )
    }
}

fun TextFieldColors.copy(other: TextFieldColors) = copy(
    focusedTextColor = other.focusedTextColor,
    unfocusedTextColor = other.unfocusedTextColor,
    disabledTextColor = other.disabledTextColor,
    errorTextColor = other.errorTextColor,
    focusedContainerColor = other.focusedContainerColor,
    unfocusedContainerColor = other.unfocusedContainerColor,
    disabledContainerColor = other.disabledContainerColor,
    errorContainerColor = other.errorContainerColor,
    cursorColor = other.cursorColor,
    errorCursorColor = other.errorCursorColor,
    textSelectionColors = other.textSelectionColors.notSameAs(unspecifiedTextSelectionColors),
    focusedIndicatorColor = other.focusedIndicatorColor,
    unfocusedIndicatorColor = other.unfocusedIndicatorColor,
    disabledIndicatorColor = other.disabledIndicatorColor,
    errorIndicatorColor = other.errorIndicatorColor,
    focusedLeadingIconColor = other.focusedLeadingIconColor,
    unfocusedLeadingIconColor = other.unfocusedLeadingIconColor,
    disabledLeadingIconColor = other.disabledLeadingIconColor,
    errorLeadingIconColor = other.errorLeadingIconColor,
    focusedTrailingIconColor = other.focusedTrailingIconColor,
    unfocusedTrailingIconColor = other.unfocusedTrailingIconColor,
    disabledTrailingIconColor = other.disabledTrailingIconColor,
    errorTrailingIconColor = other.errorTrailingIconColor,
    focusedLabelColor = other.focusedLabelColor,
    unfocusedLabelColor = other.unfocusedLabelColor,
    disabledLabelColor = other.disabledLabelColor,
    errorLabelColor = other.errorLabelColor,
    focusedPlaceholderColor = other.focusedPlaceholderColor,
    unfocusedPlaceholderColor = other.unfocusedPlaceholderColor,
    disabledPlaceholderColor = other.disabledPlaceholderColor,
    errorPlaceholderColor = other.errorPlaceholderColor,
    focusedSupportingTextColor = other.focusedSupportingTextColor,
    unfocusedSupportingTextColor = other.unfocusedSupportingTextColor,
    disabledSupportingTextColor = other.disabledSupportingTextColor,
    errorSupportingTextColor = other.errorSupportingTextColor,
    focusedPrefixColor = other.focusedPrefixColor,
    unfocusedPrefixColor = other.unfocusedPrefixColor,
    disabledPrefixColor = other.disabledPrefixColor,
    errorPrefixColor = other.errorPrefixColor,
    focusedSuffixColor = other.focusedSuffixColor,
    unfocusedSuffixColor = other.unfocusedSuffixColor,
    disabledSuffixColor = other.disabledSuffixColor,
    errorSuffixColor = other.errorSuffixColor
)

val unspecifiedTextSelectionColors = TextSelectionColors(handleColor = Color.Unspecified, backgroundColor = Color.Unspecified)